<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
  $(function() {
   var ids= getDataGridChecked("/sysUserController/selectUserRoles.html", $('#userIdFrom').text());
    var initOptions = {
      singleSelect:false,
      frozenColumns: [[
        {
          field: 'id',
          hideColumn:true
        },{
        title: '编号',
          checkbox: true,
        width: 150
      }, {
        field: 'roleName',
        title: '角色名称',
        width: 150
      }]],
      columns: [[{
        field: 'roleInfo',
        title: '角色说明',
        width: 150
      }
      ]],
      onLoadSuccess:function(row){//当表格成功加载时执行
        var rowData = row.rows;
        $.each(rowData,function(idx,val){//遍历JSON
          $.each(ids, function(index){
            if(ids[index] == val.id){
              $('#dataGridRole').datagrid("selectRow", idx);
            }
          });
        });
      }
    }
    initAjaxDataGrid("/roleController/roleManage.html", $('#dataGridRole'), initOptions);


    $('#grantsFunction').click(function () {
      parent.$.messager.progress({
        title: '提示',
        text: '数据处理中，请稍后....'
      });
      var nodesObj = $('#dataGridRole').datagrid('getChecked');
      var idArray = new Array();
      $.each(nodesObj,function(index, node){
        idArray.push(node.id +"");
      });
      var postData = {
        id:$('#userIdFrom').text(),
       roleIdsArray:idArray
      }
        $.ajax({
          url: "${pageContext.request.contextPath}/sysUserController/updateUser.html",
          type: "post",
          dataType: "json",
          data: postData,
          success: function (result) {
            parent.$.messager.progress('close');
            if (result && isSuccess(result.result)) {
              parent.$.modalDialog.openner_treeGrid.datagrid('getPager').pagination('select');
              parent.$.modalDialog.handler.dialog('close');
            }else{
              parent.$.messager.alert('提示', result.result + " " + result.message, 'info');
            }
            return false;
          },
          error: function (result) {
//			internalError();
            templateInternalError(result.responseText);
            parent.$.messager.progress('close');
            return false;
          }
        });
    });
  });
</script>
<var id="userIdFrom" style="display: none">${userId}</var>
<div class="easyui-layout" data-options="fit:true,border:false">
  <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
    <table id="dataGridRole"></table>
  </div>
</div>